package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.server.SmallVideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideosController {
    @Autowired
    private SmallVideosService smallVideosService;

      //发布视频 .接收请求体里的文件，只有接收成map或对象才需要body注解
    @PostMapping
    public ResponseEntity videos(MultipartFile videoThumbnail,MultipartFile videoFile) throws Exception {
      smallVideosService.save(videoFile,videoThumbnail);
      return ResponseEntity.ok(null);
    }

    //查询视频列表
    @GetMapping
    public ResponseEntity videoList(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10")Integer pageSize){
       PageResult pageResult = smallVideosService.slectList(page,pageSize);
       return ResponseEntity.ok(pageResult);
    }
    //为小视频点赞
    @PostMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String id){
    smallVideosService.like(id);
    return  ResponseEntity.ok(null);
    }
}
